const accountService = require('../../service/accountService.js');
const utils = require('../../utils/util.js');
// load promise 
require('../../utils/wx-pro.js');
var timer = null
const payItem = {
  closePayBox: function () {
    this.setData({
      showPayBox: false
    })
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    this.setData({
      payType: e.detail.value
    })
  },
  smsCodeChange: function (e) {
    var that = this
    that.setData({
      smsCode: e.detail.value
    })
  },
  sendCode: function(){
    this.setData({
      disableButton: true
    })
    accountService.sendMyVerifyCode().then(data => {
      if (data.code == 200) {
        wx.showToast({
          title: '发送成功',
          icon: 'succes',
          duration: 1000
        })
        timer = setInterval(() => {
          if (this.data.time == 0) {
            clearInterval(timer)
            this.setData({
              time : 60,
              codeText : '发送验证码',
              disableButton : false
            })
          } else {
            this.setData({
              time: this.data.time - 1,
              codeText: '重新发送(' + this.data.time + ')'
            })
          }
        }, 1000)
      }
    })
    .catch(() => {
      console.log('error')
    })
  },
};
export default payItem;